package com.syezon.wifikey.setting;

import android.app.Activity;
import android.arch.lifecycle.ViewModelProviders;

import com.blankj.utilcode.util.SPUtils;
import com.syezon.wifikey.ad.AdPositionEnum;
import com.syezon.wifikey.ad.BannerAd;
import com.syezon.wifikey.ad.CommonAdConfig;
import com.syezon.wifikey.ad.CommonAdViewModel;
import com.syezon.wifikey.ad.ConfigService;
import com.syezon.wifikey.ad.VideoAd;
import com.syezon.wifikey.base.LoaddingDialog;
import com.syezon.wifikey.config.TTAdManagerHolder;
import com.syezon.wifikey.web.WebHelper;

public class BookGiftHelper {

    private static final String CONFIG_NAME = "gift_config";
    private static final String IS_LOCK = "is_lock";
    private static final String FIRST_FLAG = "is_first";

    private static final String BOOK_URL = "http://novel.sharelyreader.cn/?cid=856973";

    public static void getGift(final Activity activity, final GetGiftCallBack callBack) {
        if (!isLock()) {
            WebHelper.showAd(activity, BOOK_URL, "免费小说");
            return;
        }
        boolean showAd = ConfigService.getInstance().isShowAd();
        if (showAd) {
            VideoGiftGuideDialog.showTip(activity, new VideoGiftGuideDialog.WatchVideoCallBack() {
                @Override
                public void watchVideo() {
                    callBack.getGift();
                    saveLock(false);
                }
            });
        } else {
            VideoGiftCloseAdTipDialog.showTip(activity);
        }
    }

    public static boolean isLock() {
        return SPUtils.getInstance(CONFIG_NAME).getBoolean(IS_LOCK, true);
    }

    private static void saveLock(boolean lock) {
        SPUtils.getInstance(CONFIG_NAME).put(IS_LOCK, lock);
    }

    private static boolean isFirst() {
        return SPUtils.getInstance(CONFIG_NAME).getBoolean(FIRST_FLAG, true);
    }

    private static void saveFirst(boolean first) {
        SPUtils.getInstance(CONFIG_NAME).put(FIRST_FLAG, first);
    }

    public interface GetGiftCallBack {
        void getGift();
    }
}
